**********************************
* Paper: PKO and AID
* Stata File
**********************************

* Part2 analysis *****************
use "matched_part2.dta", clear

xtset gwno_loc year

* Table 2 Model (3)
xtreg v2clrspct i.govcap_elec_earlier##c.ln_multi_aid_lag, fe
ereturn list

margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier==0)
margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier==1)


* Part2 analysis Robustness checks (Main text) ***********************************************
use "pko-aid-main-data3.dta", clear

* Instrumental variable approach (Checking weak instrument)

ivreg2 v2clrspct ln_multi_aid_lag (govcap_elec_earlier = elec_capa_mission_oth_prop total_pko_sum_lag) ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag i.gwno_loc
weakivtest

* Instrumental variable approach Table 3
ivreg2 v2clrspct ln_multi_aid_lag (i.govcap_elec_earlier##c.ln_multi_aid_lag = c.elec_capa_mission_oth_prop##c.ln_multi_aid_lag c.total_pko_sum_lag##c.ln_multi_aid_lag) ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag i.gwno_loc, first savefprefix(first)

margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans


* Table 4: Selection model
heckman v2clrspct i.govcap_elec_earlier##c.ln_multi_aid_lag ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag, select(pko_earlier = ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag) cluster(gwno_loc)

margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans


* Part2 analysis Robustness checks (Appendix: With an additional control variable) ***********************************************
use "pko-aid-main-data3.dta", clear

* Instrumental variable approach (Appendix Table J)
ivreg2 v2clrspct ln_multi_aid_lag (i.govcap_elec_earlier##c.ln_multi_aid_lag = c.elec_capa_mission_oth_prop##c.ln_multi_aid_lag c.total_pko_sum_lag##c.ln_multi_aid_lag) ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag v2cltrnslw_lag i.gwno_loc, first savefprefix(first)

margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans

* Selection model (Appendix Table K)
heckman v2clrspct i.govcap_elec_earlier##c.ln_multi_aid_lag ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag v2cltrnslw_lag, select(pko_earlier = ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag) cluster(gwno_loc)

margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans

* Part2 analysis Robustness checks (Appendix: Without UN aid) ***********************************************

* Instrumental variable approach (Appendix Table M)
ivreg2 v2clrspct ln_multi_aid_nonun_lag (i.govcap_elec_earlier##c.ln_multi_aid_nonun_lag = c.elec_capa_mission_oth_prop##c.ln_multi_aid_nonun_lag c.total_pko_sum_lag##c.ln_multi_aid_nonun_lag) ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag i.gwno_loc, first savefprefix(first)

margins, dydx(ln_multi_aid_nonun_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_nonun_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans

* Selection model (Appendix Table N)
heckman v2clrspct i.govcap_elec_earlier##c.ln_multi_aid_nonun_lag ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag, select(pko_earlier = ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag) cluster(gwno_loc)

margins, dydx(ln_multi_aid_nonun_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid_nonun_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans


* Part2 analysis Robustness checks (Appendix: removing multilateral aid that are controlled by the contributing donor governments) ***********************************************

* Instrumental variable approach (Appendix Table P)
ivreg2 v2clrspct ln_multi_aid2_lag (i.govcap_elec_earlier##c.ln_multi_aid2_lag = c.elec_capa_mission_oth_prop##c.ln_multi_aid2_lag c.total_pko_sum_lag##c.ln_multi_aid2_lag) ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag i.gwno_loc, first savefprefix(first)

margins, dydx(ln_multi_aid2_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid2_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans

* Selection model (Appendix Table Q)
heckman v2clrspct i.govcap_elec_earlier##c.ln_multi_aid2_lag ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag, select(pko_earlier = ln_year_s_start intensity_level democracy_lag ln_cgdppc_lag ln_pop_lag ln_state_aid_lag) cluster(gwno_loc)

margins, dydx(ln_multi_aid2_lag) at(govcap_elec_earlier == 0 democracy_lag == 0) atmeans
margins, dydx(ln_multi_aid2_lag) at(govcap_elec_earlier == 1 democracy_lag == 0) atmeans

